<?php
// application/forms/Article.php

class Form_Article extends Zend_Form
{

    protected $_noDecorator = array(
        'ViewHelper', 
        'Errors'
    );

    public function cluBuild($params)
    {
        // set the method for the display form to POST
        $this->setMethod('POST');
      //  die();
        
		if ($params['action'] === 'new')
		{
            $this->setAttrib('id', 'new_article');
//            $a = $params['view']->hvnUrl(array('module' => 'article', 'action'=>'new', 'view' => $this->view));
//        	$this->setAction($a);
		}
		elseif($params['action'] === 'edit')
    	{
            $this->setAttrib('id', 'edit_article');
//            $a = $params['view']->hvnUrl(array('module' => 'article', 'action'=>'edit', 'view' => $this->view));
//        	$this->setAction($a);
		}	
		
		$this->setAction($params['action_url']);
        
        $filterTrim = new Zend_Filter_StringTrim();
        $myValidator = new Zend_Validate_Regex('/^[A-Z0-9_\s\-]*$/i'); //alpha, num, space, -, _
        $myValidator->setMessage(t(60), Zend_Validate_Regex::NOT_MATCH);
        $isValidator = new Zend_Validate_Digits();
        $this->addElementPrefixPath('Clu_Filter', 'Clu/Filter/', 'filter');
        
		 
        if ($params['action'] === 'new')
		{
            //add poster id
            $poster_id = new Zend_Form_Element_Text('article_poster_id', 
                             array('disableLoadDefaultDecorators' => true,
                                   //'required'   => true,             
                                   'class' => 'inputText'));
            
            $poster_id->addDecorators($this->_noDecorator)
                  ->addValidator($isValidator);
            $this->addElement($poster_id);
            
            //add post time
            $post_time = new Zend_Form_Element_Text('article_post_time', 
                             array('disableLoadDefaultDecorators' => true,
                                 //  'required'   => true,             
                                   'class' => 'inputText'));
            
            $post_time->addDecorators($this->_noDecorator);
            $this->addElement($post_time);
		}
		
        //add story title
        $title = new Zend_Form_Element_Text('article_title', 
                         array('disableLoadDefaultDecorators' => true,
                               'required'   => true,             
                               'class' => 'inputText'));
        
        $title->addDecorators($this->_noDecorator)
              /*->addValidator($myValidator)*/;
        $this->addElement($title);
        
        //add keywords
        $keywords = new Zend_Form_Element_Text('article_keywords', 
                         array('disableLoadDefaultDecorators' => true,
                               'class' => 'inputText'));
        
        $keywords->addDecorators($this->_noDecorator)
              ->addFilter($filterTrim)
              ->addValidator($myValidator);
        $this->addElement($keywords);
        
 		//language
 		$language = new Zend_Form_Element_Select('article_language',  
                         array('disableLoadDefaultDecorators' => true,
                                'required' => true)); 
        $language->addMultiOption('vi',t(40))
               ->addMultiOption('en',t(41))
               ->addMultiOption('cn',t(42))
               ->addMultiOption('jp',t(43))
               ->addDecorators($this->_noDecorator);
        $this->addElement($language);
        
        //category
        $category = new Zend_Form_Element_Select('article_module',  
                         array('disableLoadDefaultDecorators' => true,
                                'required' => true));
        $category->addMultiOption('0','--'.t(97).'--')
               ->addMultiOption('blog',t(98))
               ->addMultiOption('forum',t(99))
               ->addMultiOption('tour',t(801))
               ->addMultiOption('place',t(701))
               ->addMultiOption('event',t(201))
               ->addMultiOption('news',t(301))
               ->addMultiOption('other',t(100))
               ->addDecorators($this->_noDecorator);
		
        $this->addElement($category);
        
        
        //story body
        $fck = new Clu_Form_Element_FckEditor('article_body', array(
        		'fckOptions' => array (
        						'Height' => 600,
        						'Width'  => 700,
        						'ToolbarSet' => 'Full'
        					)
       			 )
        );
        $fck->setLabel('Article Body');
        //$fck->addFilter($filterHtmlBody ); //TODO: if our people, maybe we don't need to filter
        $this->addElement($fck);
        
        //add update comment
        $update_comment = new Zend_Form_Element_Text('article_update_comment', 
                         array('disableLoadDefaultDecorators' => true,
                               'class' => 'inputText'));
        
        $update_comment->addDecorators($this->_noDecorator)
              ->addFilter($filterTrim)
              ->addValidator($myValidator);
        $this->addElement($update_comment);
                
        // add the submit button
		if ($params['action'] === 'new')
        	$submit = new Zend_Form_Element_Submit('submit', array('disableLoadDefaultDecorators' => true, 
                                                               'label' => t(58) ));
        else
        	$submit = new Zend_Form_Element_Submit('submit', array('disableLoadDefaultDecorators' => true, 
                                                               'label' => t(59) ));
        
        $submit->addDecorators($this->_noDecorator);
        $this->addElement($submit);
    }
}
